home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / libg_261.zip / libg_261 / libg++ / src / gen / FPlex.ccP < prev    next >
Text File  |  1992-05-29  |  4KB  |  168 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988 Free Software Foundation
  4.     written by Doug Lea (dl@rocky.oswego.edu)
  5.     based on code by Marc Shapiro (shapiro@sor.inria.fr)
  6.  
  7. This file is part of the GNU C++ Library.  This library is free
  8. software; you can redistribute it and/or modify it under the terms of
  9. the GNU Library General Public License as published by the Free
  10. Software Foundation; either version 2 of the License, or (at your
  11. option) any later version.  This library is distributed in the hope
  12. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  13. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  14. PURPOSE.  See the GNU Library General Public License for more details.
  15. You should have received a copy of the GNU Library General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #ifdef __GNUG__
  21. #pragma implementation
  22. #endif
  23. #include "<T>.FPlex.h"
  24.  
  25.  
  26. <T>FPlex:: <T>FPlex()
  27. {
  28.   lo = fnc = 0;
  29.   csize = DEFAULT_INITIAL_CAPACITY;
  30.   <T>* data = new <T>[csize];
  31.   hd = new <T>IChunk(data,  lo, lo, fnc, csize);
  32. }
  33.  
  34. <T>FPlex:: <T>FPlex(int maxsize)
  35. {
  36.   if (maxsize == 0) error("invalid constructor specification");
  37.   lo = fnc = 0;
  38.   if (maxsize > 0)
  39.   {
  40.     csize = maxsize;
  41.     <T>* data = new <T>[csize];
  42.     hd = new <T>IChunk(data,  lo, lo, fnc, csize);
  43.   }
  44.   else
  45.   {
  46.     csize = -maxsize;
  47.     <T>* data = new <T>[csize];
  48.     hd = new <T>IChunk(data,  maxsize, lo, fnc, fnc);
  49.   }
  50. }
  51.  
  52.  
  53. <T>FPlex:: <T>FPlex(int l, int maxsize)
  54. {
  55.   if (maxsize == 0) error("invalid constructor specification");
  56.   lo = fnc = l;
  57.   if (maxsize > 0)
  58.   {
  59.     csize = maxsize;
  60.     <T>* data = new <T>[csize];
  61.     hd = new <T>IChunk(data,  lo, lo, fnc, csize+lo);
  62.   }
  63.   else
  64.   {
  65.     csize = -maxsize;
  66.     <T>* data = new <T>[csize];
  67.     hd = new <T>IChunk(data,  maxsize+lo, lo, fnc, fnc);
  68.   }
  69. }
  70.  
  71. <T>FPlex:: <T>FPlex(int l, int hi, const <T&> initval, int maxsize)
  72. {
  73.   lo = l;
  74.   fnc = hi + 1;
  75.   if (maxsize >= 0)
  76.   {
  77.     csize = maxsize;
  78.     if (csize < fnc - lo)
  79.       csize = fnc - lo;
  80.     <T>* data = new <T>[csize];
  81.     hd = new <T>IChunk(data,  lo, lo, fnc, csize);
  82.   }
  83.   else
  84.   {
  85.     csize = -maxsize;
  86.     if (csize < fnc - lo)
  87.       csize = fnc - lo;
  88.     <T>* data = new <T>[csize];
  89.     hd = new <T>IChunk(data,  -csize, lo, fnc, fnc);
  90.   }
  91.   fill(initval);
  92. }
  93.  
  94. <T>FPlex::<T>FPlex(const <T>FPlex& a)
  95. {
  96.   lo = a.lo;
  97.   fnc = a.fnc;
  98.   csize = fnc - lo;
  99.   if (csize < a.csize) csize = a.csize;
  100.   <T>* data = new <T> [csize];
  101.   hd = new <T>IChunk(data,  lo, lo, fnc, lo+csize);
  102.   for (int i = a.low(); i < a.fence(); a.next(i)) (*this)[i] = a[i];
  103. }
  104.  
  105. void <T>FPlex::operator= (const <T>FPlex& a)
  106. {
  107.   if (&a != this)
  108.   {
  109.     del_chunk(hd);
  110.     lo = a.lo;
  111.     fnc = a.fnc;
  112.     csize = fnc - lo;
  113.     if (csize < a.csize) csize = a.csize;
  114.     <T>* data = new <T> [csize];
  115.     hd = new <T>IChunk(data,  lo, lo, fnc, lo+csize);
  116.     for (int i = a.low(); i < a.fence(); a.next(i)) (*this)[i] = a[i];
  117.   }
  118. }
  119.  
  120.  
  121. void <T>FPlex::reverse()
  122. {
  123.   <T> tmp;
  124.   int l = lo;
  125.   int h = fnc - 1;
  126.   while (l < h)
  127.   {
  128.     tmp = (*this)[l];
  129.     (*this)[l] = (*this)[h];
  130.     (*this)[h] = tmp;
  131.     next(l);
  132.     prev(h);
  133.   }
  134. }
  135.  
  136. void <T>FPlex::fill(const <T&> x)
  137. {
  138.   for (int i = lo; i < fnc; ++i) (*this)[i] = x;
  139. }
  140.  
  141. void <T>FPlex::fill(const <T&> x, int lo, int hi)
  142. {
  143.   for (int i = lo; i <= hi; ++i) (*this)[i] = x;
  144. }
  145.  
  146. void <T>FPlex::clear()
  147. {
  148.   if (fnc != lo)
  149.   {
  150.     hd->clear(lo);
  151.     fnc = lo;
  152.   }
  153. }
  154.  
  155. int <T>FPlex::OK () const
  156. {
  157.   int v = hd != 0;                    // hd exists
  158.   v &= hd-><T>IChunk::OK();           // and is OK
  159.   v &= fnc - lo <= hd->size();        // and has enough space
  160.   v &= lo <= fnc;                     // plex indices consistent
  161.   v &= lo == hd->low_index();         // and match those 
  162.   v &= fnc == hd->fence_index();      //   of chunk
  163.   v &= one_chunk();                   // and only one chunk
  164.   if (!v) error("invariant failure");
  165.   return v;
  166. }
  167.  
  168.